package edu.ynu.se.xiecheng.achitectureclass.entity;

import edu.ynu.se.xiecheng.achitectureclass.common.entity.LogicEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.*;
import java.util.Date;

/**
 * 氮含量数据实体类
 * 用于存储土壤中氮含量的测量数据
 */
@Data
@Entity
@Table(name = "nitrogen_level")
@EqualsAndHashCode(callSuper = true)
public class NitrogenLevel extends LogicEntity {
    /**
     * 关联的设备
     * 氮含量数据与设备的多对一关系
     */
    @ManyToOne
    @JoinColumn(name = "equipment_id", nullable = false)
    private Equipment equipment;

    /**
     * 数据名称
     * 例如："土壤氮含量测量"
     */
    @Column(name = "measurement_name")
    private String measurementName;

    /**
     * 氮含量值
     * 非空
     */
    @Column(name = "nitrogen_value", nullable = false)
    private Double nitrogenValue;

    /**
     * 创建时间
     * 自动记录数据的创建时间
     */
    @Column(name = "recorded_time")
    @Temporal(TemporalType.TIMESTAMP)
    private Date recordedTime;

    /**
     * 在持久化之前自动设置创建时间
     */
    @PrePersist
    protected void onCreate() {
        recordedTime = new Date();
    }
}